package com.eqdd.yiqidian.ui.gongneng.renshi.kaoqin.setting;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;

import com.eqdd.yiqidian.AddTimeActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.EditBean;
import com.eqdd.yiqidian.bean.FourBean;
import com.eqdd.yiqidian.ui.base.BaseMultiEditActivity;
import com.eqdd.yiqidian.utils.ToastUtil;

import java.util.ArrayList;

public class AddTimeActivity extends BaseMultiEditActivity {
    private AddTimeActivityCustom dataBinding;
    private String[] titles = new String[]{
            "上班时间",
            "上班打卡时间",
            "下班时间",
            "下班打卡时间"
    };
    private String[] hintTexts = new String[]{
            "请选择",
            "请选择",
            "请选择",
            "请选择"
    };
    private int[] types = new int[]{
            5, 1, 5, 1
    };
    private String[] contents;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_add_time);
        initTopTitleBar(View.VISIBLE, "添加打卡时间");
        initTopRightText("完成", v -> {
            if (checkInfo()) {
                Intent intent = new Intent();
                intent.putExtra(Config.START_TIME, editBeans.get(0).getContent());
                intent.putExtra(Config.START_TIME_RANGE, editBeans.get(1).getContent());
                intent.putExtra(Config.END_TIME, editBeans.get(2).getContent());
                intent.putExtra(Config.END_TIME_RANGE, editBeans.get(3).getContent());
                if (contents==null) {
                    setResult(Config.SUCCESS, intent);
                }else {
                    setResult(Config.CHANGE,intent);
                }
                finish();
            } else {
                ToastUtil.showShort("信息不完整");
            }
        });
    }

    private boolean checkInfo() {
        for (int i = 0; i < editBeans.size(); i++) {
            if (TextUtils.isEmpty(editBeans.get(i).getContent())) {
                return false;
            }
        }
        return true;
    }

    @Override
    public void initData() {
        FourBean fourBean =getIntent().getParcelableExtra(Config.FOUR_BEAN);
        if (fourBean != null) {
            contents = new String[]{
                    fourBean.getFirst(),
                    fourBean.getSecond(),
                    fourBean.getThird(),
                    fourBean.getFour()
            };
        }
        for (int i = 0; i < titles.length; i++) {
            EditBean editBean = new EditBean();
            editBean.setTitle(titles[i]);
            editBean.setType(types[i]);
            editBean.setContent(contents != null ? contents[i] : "");
            editBean.setTextTitle(titles[i]);
            editBean.setHint(hintTexts[i]);
            editBeans.add(editBean);
            switch (i) {
                case 1:
                    editBean.setChooseItem(getResources().getStringArray(R.array.tiqianTime));
                    break;
                case 3:
                    editBean.setChooseItem(getResources().getStringArray(R.array.yanhouTime));
                    break;
            }
        }
        if (quickAdapter != null) {
            ArrayList<EditBean> temp = new ArrayList<>();
            temp.addAll(editBeans);
            quickAdapter.notifyDataChanged(temp, true);
        }
    }

    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }

    @Override
    public void saveData() {

    }
}
